package com.twu.biblioteca.movie;

import com.twu.biblioteca.item.Field;
import com.twu.biblioteca.item.Item;
import com.twu.biblioteca.message.Message;
import com.twu.biblioteca.utils.StringUtils;

/**
 * Created by Enrico on 15/09/2014.
 */
public class Movie extends Item {

    private static final String MOVIE_FORMAT = "|%1$-" + Field.NAME.getSize() +
            "s|%2$-" + Field.AUTHOR.getSize() +
            "s|%3$-" + Field.YEAR.getSize() +
            "s|%4$-" + Field.RATING.getSize() +
            "s|";

    private Rating rating;

    public Movie(String name, int year, String director, double score) {
        super(name, director, year);
        rating = new Rating(score);
    }

    public double getRating(){
        return rating.getScore();
    }

    public void showCheckoutMessage(){
        String message = (available)
                ? Message.SUCCESSFUL_MOVIE_CHECKOUT.getText()
                : Message.UNSUCCESSFUL_MOVIE_CHECKOUT.getText();
        System.out.println(message);
    }

    public void showReturnMessage(){
        String message = (!available)
                ? Message.SUCCESSFUL_MOVIE_RETURN.getText()
                : Message.UNSUCCESSFUL_MOVIE_RETURN.getText();
        System.out.println(message);
    }

    @Override
    public String toString() {
        return "Movie";
    }

    @Override
    public String formatted() {
        return String.format(MOVIE_FORMAT, " " + name, " " + author,
                " " + year, " " + rating.toString());
    }

    @Override
    public void showHeader() {
        String header = String.format(MOVIE_FORMAT,
                StringUtils.center("Name", Field.NAME.getSize()),
                StringUtils.center("Director(s)", Field.AUTHOR.getSize()),
                StringUtils.center("Year", Field.YEAR.getSize()),
                StringUtils.center("Rating", Field.RATING.getSize()));
        System.out.println(header);
    }

}
